import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/club_ranking/club_ranking_controller.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

class ClubRankingItem extends StatelessWidget {
  const ClubRankingItem({
    super.key,
    this.onTap,
    this.rankingWidget,
    this.index = 0
  });

  final Function? onTap;

  final Widget? rankingWidget;

  final int index;


  @override
  Widget build(BuildContext context) {
    return GetBuilder<ClubRankingController>(
      builder: (clubRankingController) {
        return GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            onTap?.call();
          },
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 12.w),
            child: Row(
              children: [
                Container(
                  width: 88.w,
                  height: 88.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10.r),
                  ),
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(10.r),
                    child: Image.network(clubRankingController.clubRankList[index].clubImage ?? '', fit: BoxFit.fill, gaplessPlayback: true, excludeFromSemantics: true,),
                  ),
                ),

                SizedBox(width: 10.w,),

                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(top: 3.w),
                    height: 90.w,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          child: Text(clubRankingController.clubRankList[index].clubName ?? '', style: TextStyle(fontSize: 15.sp, fontWeight: FontWeight.bold, color: const Color(0xff333333)), maxLines: 1, overflow: TextOverflow.ellipsis,),
                        ),
                        SizedBox(height: 4.w,),
                        Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(8.r),
                            color: const Color(0xff499360 ).withOpacity(0.08)
                          ),
                          padding: EdgeInsets.symmetric(vertical: 1.w, horizontal: 6.w),
                          child: Text(clubRankingController.clubRankList[index].clubSportsName ?? '', style: TextStyle(fontSize: 10.sp, color: const Color(0xff499360)),),
                        ),
                        SizedBox(height: 4.w,),
                        SizedBox(
                          child: Text(clubRankingController.clubRankList[index].clubAddress ?? '', style: TextStyle(fontSize: 12.sp, color: const Color(0xff666666)),),
                        ),
                
                        const Spacer(),
                
                        SizedBox(
                          child: Row(
                            children: [
                              _tagWidget(text: '活跃${clubRankingController.clubRankList[index].liveness ?? 0}', icon: 'assets/images/img_hyd.png'),
                
                              SizedBox(width: 40.w,),
                
                              _tagWidget(text: '${clubRankingController.clubRankList[index].playerNum ?? 0}人', icon: 'assets/images/img_feed_rs.png'),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                ),

                rankingWidget!
              ],
            ),
          ),
        );
      }
    );
  }

  _tagWidget({
    String icon = '',
    String text = ''
  }) {
    return SizedBox(
      child: Row(
        children: [
          SizedBox(
            width: 12.w,
            height: 12.w,
            child: Image.asset(icon),
          ),
          SizedBox(width: 5.w,),
          SizedBox(
            child: Text(text, style: TextStyle(fontSize: 12.sp, color: const Color(0xff999999)),),
          )
        ],
      ),
    );
  }

}